using System;
using System.Configuration;

namespace KodeIT.Web.Configuration
{
    [ConfigurationCollection(typeof(HttpFilterElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
    public sealed class HttpFilterCollection : ConfigurationElementCollection
    {
        #region Statics

        private static ConfigurationPropertyCollection _properties;

        public HttpFilterCollection()
        {
            _properties = new ConfigurationPropertyCollection();
        }

        #endregion

        #region Properties

        protected override ConfigurationPropertyCollection Properties
        {
            get { return _properties; }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get { return ConfigurationElementCollectionType.AddRemoveClearMap; }
        }

        #endregion

        #region Indexers

        public HttpFilterElement this[int index]
        {
            get { return (HttpFilterElement)base.BaseGet(index); }
            set
            {
                if (null != base.BaseGet(index))
                {
                    base.BaseRemoveAt(index);
                }

                base.BaseAdd(index, value);
            }
        }

        public new HttpFilterElement this[string name]
        {
            get { return (HttpFilterElement)base.BaseGet(name); }
        }

        #endregion

        #region Overrides

        protected override ConfigurationElement CreateNewElement()
        {
            return new HttpFilterElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return (element as HttpFilterElement).Name;
        }

        #endregion
    }
}
